<?php
/**
 * Miffos framework
 * ----------------------------------------------
 *
 * Copyright (c) 2008, 2009 Martin Sadový (http://sodae.cz)
 *
 * This source file is subject to the "Miffos license" that is bundled
 * with this package in the file license.txt.
 *
 * @copyright  Copyright (c) 2008, 2009 Martin Sadový
 * @license    license.txt
 * @link       http://miffos.sodae.cz
 * @package    miffos
 * @version    $Id$
 */


require_once dirname(__FILE__).'/Cache/FileCache.php';

class Cache implements ArrayAccess{
    
    
    public static $dir = 'cache/';
    
    private $data;
    
    public function __construct($namespace,$type='File')
    {
        $name =  $type.'Cache';
        $this->data = new $name($namespace);
    }
    
    
    
    /**
     * Save cache data
     * @param int $expire
     */              
    public function expire($expire = 3600)
    {
        $this->data->expire($expire);
    }
    
    
    
    /**
     * interface ArrayAccess
     */                  
    public function offsetSet($offset, $value)
    {   
        if(is_null($value) ){
           $this->data->remove($offset);
        }else{
           $this->data->set($offset, $value);
        }
    }
    
    public function offsetExists($offset)
    {
        return !is_null($this->data->get($offset));
    }
    
    public function offsetUnset($offset) 
    {
        $this->data->remove($offset);
    }
    
    public function offsetGet($offset) 
    {
        return $this->data->get($offset);
    }
    
}
?>
